<%-- 
    Document   : admin_schedule
    Created on : 2020-5-28, 9:44:51
    Author     : liqianru
--%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>管理带课</title>
        <!--图标样式-->
        <link rel="stylesheet" href="css/bootstrap.min.css"/>
        <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
        <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@3.3.7/dist/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
        <!--主要样式-->
        <link rel="stylesheet" type="text/css" href="css/style.css" />
        <link rel="stylesheet" href="css/bootstrap.min.css"/>
        <link rel="stylesheet" href="css/mycss_foradim.css"/>
        <script type="text/javascript" src="js/jquery-3.4.1.min.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/circle.js" charset="UTF-8"></script>
    </head>
    <body onload="goPage(1, 10)">
        <script>
            $(function () {
                setInterval(function () {

                    $.ajax({
                        url: 'admin_modifyStatus',
                        type: 'post',
                        async: false,
                        data: {admin_action: "search_status"},
                        success: function (data) {//status 表示申请状态：：0表示未申请
                            if (data < 1) {

                                $(".redpoint").css("display", "inline-block");
                                $("#status_li").css("display", "block");

                            }
                            if (data > 0) {
                                $(".redpoint").css("display", "none");
                                $("#status_li").css("display", "none");
                            }

                        },
                        error: function () {
                          //  alert("error");
                        }

                    });
                }, 500);
            });

        </script>
        <div id="navdiv">
            <div class="top_navdiv">
                <div class="top_left">管理员中心</div>
                <div class="identity">
                    <span class="message">您好</span><span class="redpoint">1</span>
                    <div class="user_li">
                        <canvas id="myCanvas" width="100" height="30">
                        </canvas>
                    </div>
                    <div class="nd_menu">
                        <ol>
                            <li>回到首页</li>
                            <li><a href="#" onclick="all_logout()">退出登录</a></li>
                            <li id="status_li"><a onclick="refresh()" href="#" data-target="#myModal_status" data-toggle="modal">申请信息</a><span class="redpoint" id="status_span">1</span></li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
        <div class=" control_nav ">
            <div class="container">
                <ul class="nav navbar-nav navul">

                    <li class="col-md-2 nav_li">
                        <a href="#"><img class="nav_img" src="img/nav6.png"/> 教师</a>
                        <div class="nav_underline" style="display: none;"></div>
                    </li>
                    <li class="col-md-2 nav_li">
                        <a href="#"><img class="nav_img" src="img/nav1.png"/> 班级</a>
                        <div class="nav_underline" style="display: none;"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getallStu?action=getall"><img class="nav_img" src="img/nav5.png"/> 学生</a>
                        <div class="nav_underline" style="display: none;"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getallCourse?action1=getall"><img class="nav_img" src="img/nav3.png"/> 课程</a>
                        <div class="nav_underline" style="display: none;"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getallschedule"><img class="nav_img" src="img/nav2.png"/> 带课</a>
                        <div class="nav_underline" style="display: block"></div>
                    </li>
                    <li class="col-md-2">
                        <a href="getTest?action=get"><img class="nav_img" src="img/nav4.png"/> 题目</a>
                        <div class="nav_underline" style="display: none;"></div>
                    </li>

                </ul>
            </div>
        </div>
        <div class="container">
            <div class="col-md-3 ">
                <div class="question_bank main_div nav_list">
                  
                    <span><b>管理员</b></span>
                    <div class="div_line"></div>
                    <ul>
                        <li>
                            <img class="img-circle" width="74px" height="70px;" src="img/login_img.jpg" alt="管理员">
                        </li>
                        <li>
                            <span class="signature" id="admin-signature">Hi,又是充满活力的一天</span><a title="点击更换个性签名" href="javascript:changeAdminSignature(Math.floor(Math.random()*5));"><img src="img/admin_about.png" alt="关于" width="15px" height="15px"></a>
                        </li>
                        <li>
                            <a href="admin_getGrade?action=getall"><img src="img/admin_user.png" alt="user" title="查看成绩" width="20px" height="20px"></a>
                            <a href="index.html"><img src="img/admin_home.png" alt="回到首页" width="20px" height="20px"></a>
                            <a href="getTest?action=get"><img src="img/admin_case.png" alt="题库管理" title="题库管理" width="20px" height="20px"></a>
                            <a href="getallStu?action=getall"><img src="img/admin_customer1.png" alt="管理学生" title="管理学生" width="20px" height="20px"></a>
                        </li>
                        <li>
                            <a href="#" id="nd-title">思修</a><span class="glyphicon glyphicon-chevron-right"></span>
                        </li>
                    </ul>
                </div>
            </div>
   
            <div class="col-md-9 main_div ">
                <form>
                    <input type="text" class="input-lg" name="keyword" placeholder="输入关键字查询" id="keyword_input">
                    <input type="text" hidden name="action" value="searchS">
                    <button  class="btn btn-lg btn-toolbar search_btn" formaction="getCoursebykeyword" formmethod="get" >
                        <span class="glyphicon glyphicon-search"></span>
                    </button>
                    <button class="btn btn-sm add_text_btn" type="button" data-target="#myModal" data-toggle="modal">
                        <span class="glyphcion glyphicon-plus">添加课程</span>
                    </button>
                    <button class="btn btn-sm re_Stu_btn re_text_btn" formaction="getallschedule" formmethod="GET">
                        <span class="glyphicon glyphicon-repeat">刷新列表</span>
                    </button>
                </form>
                <!---弹窗-  添加课程-->
                <!-- Modal -->
                <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">添加课程</h4>
                            </div>
                            <div class="modal-body">
                                <form id="add_form">
                                    <label for="courseid">请输入课程编号：</label>
                                    <input type="number" id="courseid" class="form-control input-sid" name="courseid">
                                    <label for="tid">请输入任课教师编号：</label>
                                    <input type="number" id="tid" class="form-control input-sid" name="tid">
                                    <label for="classid">请选择班级</label>
                                    <select id="classid" class="form-control" name="classid">
                                        <option value="2018001">18软件J01</option>
                                        <option value="2018002">18软件J02</option>
                                        <option value="2018003">18软件J03</option>
                                    </select>
                                    <input type="text" hidden name="action" value="addSchedule"/>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary" id="submit_btn" onclick="submit()">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--编辑弹窗-->
                <div class="modal fade" id="myModal_modify" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog">
                        <div class="modal-content modal_div">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">修改课程</h4>
                            </div>
                            <div class="modal-body">
                                <form id="modify_form" class="modal_form">
                                    <label for="coursename">课程名：</label>
                                    <input type="text" id="coursename" class="form-control input-lg" name="coursename" readonly>
                                    <label for="courseid">课程编号：</label>
                                    <input type="text" id="courseid" class="form-control" name="courseid" readonly>
                                    <label for="tid">请修改任课教师编号：</label>
                                    <input type="text" id="tid" class="form-control" name="tid">
                                    <label for="classid">请修改班级</label>
                                    <select id="classid" class="form-control" name="classid">
                                        <option value="2018001">18软件J01</option>
                                        <option value="2018002">18软件J02</option>
                                        <option value="2018003">18软件J03</option>
                                    </select>
                                    <input type="text" hidden name="action" value="updateSchedule"/>
                                </form>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary" id="submit_btn" onclick="modify()">提交</button>
                            </div>
                        </div>
                    </div>
                </div>
                <!--编辑确认窗口-->
                <div class="modal fade" id="myModal_status" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">确认</h4>
                            </div>
                            <div class="modal-body">
                                <p>确认批准考试编号为:<b>${sessionScope.testid}</b>的申请吗？</p>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-primary" id="submit_btn" onclick="modify_status(${sessionScope.testid})">确认</button>
                                <button type="button" class="btn btn-default" id="submit_btn" data-dismiss="modal">取消</button>
                            </div>
                        </div>
                    </div>
                </div>
                <table class="mytable" id="Stu_table">
                    <thead class="thead">
                        <tr class="col_head">
                            <th scope="col" class="col_head_3">班级</th>
                            <th scope="col" class="col_head_3">课程名</th>
                            <th scope="col" class="col_head_3">任课教师</th>
                            <th scope="col" class="col_head_1">操作</th>
                        </tr>
                    </thead>
                    <tbody>
                        <c:forEach items="${sessionScope.allCourse}" var="c">
                            <tr id="tr${c.courseId}">
                                <td hidden id="cid${c.courseId}">${c.courseId}</td>
                                <td id="classname${c.courseId}">${c.className}</td>
                                <td id="cname${c.courseId}">${c.courseName}</td>
                                <td id="tname${c.courseId}">${c.teacherName}</td>
                                <td id="tid${c.courseId}" hidden>${c.tid}</td>
                                <td><a href="#" onclick="showCoursedetail('${c.courseId}')" class="delete_a text-success" data-target="#myModal_modify" data-toggle="modal">编辑</a> <a href="javascript:deleteSchedule('${c.courseId}')" class="delete_a text-danger">删除</a></td>
                            </tr>
                        </c:forEach>
                    </tbody>
                </table>
                <div id="barcon" name="barcon" class="index_div"></div>
            </div>

        </div>
        <script>
            function showCoursedetail(cid) {
                $("#modify_form #coursename").val($("#cname" + cid).text());
                $("#modify_form #courseid").val($("#cid" + cid).text());
                $("#modify_form #tid").val($("#tid" + cid).text());


            }
            function submit() {
                $.ajax({
                    url: "operaCourse",
                    type: 'POST',
                    data: $("#add_form").serialize(),
                    success: function (row) {
                        if (row > 0) {
                            alert("success");
                            $("#myModal").modal('hide');
                            window.location.reload();
                        }
                    },
                    error: function () {
                        alert("error");
                        $("#myModal").modal('hide');
                    }
                });
            }
            function deleteSchedule(courseid) {
                $.ajax({
                    url: "operaCourse",
                    type: 'POST',
                    data: {action: "deleteSchedule", cid: courseid},
                    success: function (rows) {
                        if (rows > 0) {
                            $("#tr" + courseid).remove();
                        }
                    },
                    error: function (error) {
                        alert("error" + error);
                    }
                });
            }
            function modify() {
                $.ajax({
                    url: "operaCourse",
                    type: "POST",
                    data: $("#modify_form").serialize(),
                    success: function (row) {
                        if (row > 0) {
                            alert("success");
                            $("#myModal_modify").modal('hide');
                            window.location.reload();
                        }
                    },
                    error: function () {
                        alert("error");
                    }
                });
            }
            function modify_status(testid){
                     $.ajax({
                        url: 'admin_modifyStatus',
                        type: 'post',
                        async: false,
                        data: {admin_action: "modify_status"},
                        success: function (data) {//status 表示申请状态：：0表示未申请
                            $("#myModal_status").modal('hide');
                            
                        },
                        error: function () {
                            alert("error");
                        }

                    });               
            }
        </script>
    </body>
</html>
